/*
 * @Date: 2021-12-12 19:47:04
 * @LastEditors: LeeKing
 * @LastEditTime: 2021-12-13 21:18:16
 * @FilePath: \admin\src\permission.js
 */

import router from '@/router'
import store from '@/store'
// 路由导航守卫
router.beforeEach(function(to, from, next) {
  const token = store.state.user.token
  const nextTo = ['/404', '/login']
  if (token) {
    if (to.path === '/login') return next('/')
    // store.dispatch('user/getUserInfo')
    next()
  } else {
    if (nextTo.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
